// pages/tabBar/index/index.js
import tui from './../../../common/httpRequest'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl:' https://image.anji-navinfo.cn/group1/M00/9F/9F/img/img_nodata.png',
    isActive:'0',//btnactive
    taskbg: ' https://image.anji-navinfo.cn/group1/M00/9F/9F/img/bg.jpg',
    list: [
     
    ],
    btn_list:[
      {
        name:'需审核',
        type:'0',
      },
      {
        name:'待审核',
        type:'1',
      },
      {
        name:'已驳回',
        type:'2',
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      isActive:'0'
    })
    getApp().globalData.ifHide='2'
    getApp().globalData.searchName=''

    wx.setStorageSync('searchName','');
    // console.log(getApp().globalData.ifHide,'wxamine')
    this.getHeight()

  },
  async getList() {
    // console.log(this.data.isActive,'this.data.isActive')
    const res = await tui.request('sys/task/reviewList', 'GET', {
      name:wx.getStorageSync('name'),
      menuStatus: Number(this.data.isActive+1),
    }, true);
    this.setData({
      list: []
    })
    if (res.code == 20000) {
      this.setData({
        list: res.data
      })
    }
  },
  // e
  changeBtn(e){
    this.setData({
      isActive:e.target.dataset.index
    })
    this.getList()
  },
  getHeight() {
    const capsuleInfo = wx.getMenuButtonBoundingClientRect();//胶囊信息
    const systemInfo = wx.getSystemInfoSync(); // 获取设备信息
    const statusHeight = systemInfo.statusBarHeight // 状态栏高度
    const clientHeight = systemInfo.windowHeight, clientWidth = systemInfo.windowWidth, rpxR = 750 / clientWidth;
    const calc = clientHeight * rpxR;
    this.setData({
      winHeight: calc,
      height: capsuleInfo.height,
      statusHeight: statusHeight,
      top: (capsuleInfo.top + statusHeight) / 2,
      topD: 45 + statusHeight,
      heightList: clientHeight - 154 - 50 - 40-40
    })
    // console.log(capsuleInfo.top, statusHeight)
  },
  toPage(e){
    if(this.data.isActive==0){
      let item=e.currentTarget.dataset.item
      // console.log(e,item,'asdasdsa')
      let a=item.taskState=='1'||item.taskState=='2'?'新增':'完成'
      console.log(a,'aaaaa')
      wx.navigateTo({
        url: '/packages/task/detail/index?id=' + e.target.dataset.id+'&type='+'审核'+'&taskStateName='+a,
      })
    }else{
      wx.navigateTo({
        url: '/packages/task/detail/index?id=' + e.target.dataset.id+'&type='+'详情'+'&isActive='+this.data.isActive,
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
   

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        current: '2',
        ['tabBar[2].num']:getApp().globalData.ifExemine
      })
    }
    this.setData({
      isActive:'0'
    })
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})